package cc.sjfx.sharedoc.bmob;

import android.content.Context;
import cc.sjfx.sharedoc.cache.UserCache;
import cc.sjfx.sharedoc.db.bmob.User;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.listener.UpdateListener;
import cn.mandroid.frame.toast.MLog;
import cn.mandroid.frame.tools.MD5;

public class SessionToken {
	public static String  get(String s) {
		s=s+System.currentTimeMillis();
		String session=MD5.getMd5Code(s);
		MLog.i(session);
		return session;
	}
	public static void update(final Context context) {
		User user = new User();
		user.setSessionId(SessionToken.get(BmobUser.getCurrentUser(context).getUsername()));
		user.update(context, BmobUser.getCurrentUser(context).getObjectId(),
				new UpdateListener() {

					@Override
					public void onSuccess() {
						// TODO Auto-generated method stub
						UserCache.user = BmobUser.getCurrentUser(context,
								User.class);
						UserCache.isLogin = true;
					}

					@Override
					public void onFailure(int arg0, String arg1) {
						// TODO Auto-generated method stub

					}
				});
	}
}
